function walk(ast, { exit, enter }) {
  if (ast.children && ast.children.length === 0) {
    exit(ast);
  } else if (ast.type === "Text" || ast.type === "MustacheTag") {
    exit(ast);
  } else {
    ast.children.forEach(node => {
      node.parent = ast;
      enter(node);
      walk(node, { enter, exit });
    });
    exit(ast);
  }
}

module.exports = walk;